package com.ruoyi.system.util;

import org.apache.commons.lang.StringUtils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class KeyWordUtils {
    /**
     * 拆分【与】关键字
     * @param preKeyWords
     * @return
     */
    public static List<String> transformationAnd(String preKeyWords){
        List<String> keys=new ArrayList<>();
        if(StringUtils.contains(preKeyWords,"*")){
            keys = Arrays.asList(preKeyWords.split("\\*"));
        }else{
            keys.add(preKeyWords);
        }
        return keys;
    }

    /**
     * 拆分【或】关键字
     * @param preKeyWords
     * @return
     */
    public static List<String> transformationOr(String preKeyWords){
        List<String> keys=new ArrayList<>();
        if(StringUtils.contains(preKeyWords,",")){
            keys = Arrays.asList(preKeyWords.split(","));
        }else{
            keys.add(preKeyWords);
        }
        return keys;
    }


    /**
     * 拆分所有关键字
     * @param preKeyWords
     * @return
     */
    public static List<String> transformation(String preKeyWords){
        List<String> keys=new ArrayList<>();
        //统一','隔开
        preKeyWords=preKeyWords.replace("*",",");
        if(StringUtils.contains(preKeyWords,",")){
            keys = Arrays.asList(preKeyWords.split(","));
        }else{
            keys.add(preKeyWords);
        }
        return keys;
    }

}
